﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
using WWB.SitePointPrivateMessages.Core.Model.DataImport;
using WWB.SitePointPrivateMessages.Core.Service;

namespace WWB.SitePointPrivateMessages.Tests.DataImportTests.Xml
{
    [TestFixture]
    public class XmlSerializationTests
    {
        [Test]
        public void Can_deserialize_from_xml()
        {
            var dis = new XmlFileImportExportService();
            var export = dis.GetMessagesFromXml(@".\SourceData\Sample.xml");
            Assert.That(export, Is.Not.Null);
            Assert.That(export.Folders.Count(), Is.EqualTo(5));
            Assert.That(export.Folders[0].Name, Is.EqualTo("Sent Items"));
        }

        [Test]
        public void Can_deserialize_and_reserialize()
        {
            var dis = new XmlFileImportExportService();
            var export = dis.GetMessagesFromXml(@".\SourceData\Sample.xml");
            var xdoc = dis.SerializeMessages(export);
            xdoc.Save(@".\exported.xml");

            var reimported = dis.GetMessagesFromXml(@".\exported.xml");
            for (int i = 0; i< reimported.Folders.Length; i++)
            {
                Assert.That(reimported.Folders[i].Name, Is.EqualTo(export.Folders[i].Name));
                Assert.That(reimported.Folders[i].Messages.Count(), Is.EqualTo(export.Folders[i].Messages.Count()));
            }
        }

    }
}
